package cn.edu.zut.internship.web.controller.sys;


import cn.edu.zut.internship.bean.sys.Result;
import cn.edu.zut.internship.entity.AuthSysResources;
import cn.edu.zut.internship.iservice.sys.IResourceService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/resource")
public class PermResourceController {
    @Reference
    private IResourceService resourceService;
    @GetMapping("/search")
    public Result searchResources(){
        Result result = new Result();
        List<AuthSysResources> resourcesList = this.resourceService.searchAllResources();
        result.setBeans(resourcesList);
        return result;
    }

    @GetMapping("/search/{id}")
    public Result searchResource(@PathVariable("id") Long id){
        Result result = new Result();
        AuthSysResources resources = this.resourceService.searchResource(id);
        result.getBean().put("resources",resources);
        return result;
    }

    @PostMapping("/create")
    public Result addResource(@RequestBody AuthSysResources resources){
        Result result = new Result();
        this.resourceService.addResource(resources);
        return result;
    }

    @PutMapping("/update")
    public Result updateResource(@RequestBody AuthSysResources resources){
        Result result = new Result();
        this.resourceService.updateResource(resources);
        return result;
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteResource(@PathVariable("id") Long id){
        Result result = new Result();
        this.resourceService.deleteResource(id);
        return result;
    }
}
